﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;

namespace GPCSC.Web.sjsbyes
{
    public partial class NewMQList : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                f_buildGrid();
            }
        }
        protected void f_buildGrid()
        {
            Hashtable htable = new Hashtable();
            //htable.Add("@BTSBLMName", "3");
            DataSet ds = new DataReturn().ReturnData(htable, "sel_newsMQ_all");

            if (ds != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dbRow in ds.Tables[0].Rows)
                    {
                        if (dbRow["EditUrl"] != null)
                        {
                            dbRow["EditUrl"] = "NewMQEdit.aspx?Command=Edit";
                        }

                        if (dbRow["ViewUrl"] != null)
                        {
                            dbRow["ViewUrl"] = "NewMQEdit.aspx?Command=View";
                        }
                    }
                }
                PostListS.DataSource = ds;
                PostListS.DataBind();
                this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

            }
        }
        /// <summary>
        /// Callback异步加载数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void LCallBack_Callback(object sender, NickLee.Web.UI.CallBackEventArgs e)
        {
            SqlReadXml org = new SqlReadXml();
            try
            {
                #region 删除数据
                if (Usual.f_convertString(e.Parameters[0]) == "3")
                {
                    SqlReadXml Org = new SqlReadXml();
                    var allname = "";
                    var deptname = "";
                    try
                    {

                        var zid = Usual.f_convertString(e.Parameters[2]);
                        if (zid == "" || zid == null)
                        {

                        }
                        base.o_uiTable.Clear();
                        base.o_uiTable.Add("@tabids", zid);

                        //先查找有无子部门


                        //删除此部门
                        if (deptname == "")
                        {
                            Org.NotDoSQL("del_newsMQ_byid", base.o_uiTable);
                            hfError.Value = lblProcesserMsg.Text = "删除数据成功!";
                        }
                        this.f_buildGrid();
                    }
                    catch (System.Exception ee)
                    {
                        hfError.Value = lblProcesserMsg.Text = "删除数据失败!" + ee.Message;

                    }
                }

                else if (Usual.f_convertString(e.Parameters[0]) == "2")
                {
                    SqlReadXml Org = new SqlReadXml();//
                    var zid = Usual.f_convertString(e.Parameters[2]);
                    if (zid == "" || zid == null)
                    {
                        this.f_buildGrid();
                    }
                    else
                    {
                        string likes = e.Parameters[2].ToString();
                        likes = "%" + likes + "%";
                        Hashtable htable = new Hashtable();
                        htable.Add("@like", likes);

                        DataSet ds = Org.ReaderDataSet("sel_newsMQ_bylike", htable);

                        if (ds != null)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                foreach (DataRow dbRow in ds.Tables[0].Rows)
                                {
                                    if (dbRow["EditUrl"] != null)
                                    {
                                        dbRow["EditUrl"] = "MQRJTJEdit.aspx?Command=Edit";
                                    }

                                    if (dbRow["ViewUrl"] != null)
                                    {
                                        dbRow["ViewUrl"] = "MQRJTJEdit.aspx?Command=View";
                                    }
                                  
                                }
                            }
                            PostListS.DataSource = ds;
                            PostListS.DataBind();
                            this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

                        }

                    }
                }
                else if (Usual.f_convertString(e.Parameters[0]) == "sel")
                {
                    SqlReadXml Org = new SqlReadXml();//
                    var zid = Usual.f_convertString(e.Parameters[2]);

                    string likes = e.Parameters[1].ToString().Trim();
                    likes = "%" + likes + "%";
                    Hashtable htable = new Hashtable();
                    htable.Add("@like", likes);
                    string zzs = e.Parameters[2].ToString().Trim();
                    zzs = "%" + zzs + "%";
                    string fbs = e.Parameters[3].ToString().Trim();
                    fbs = "%" + fbs + "%";
                    string cont = e.Parameters[4].ToString().Trim();
                    cont = "%" + cont + "%";
                    htable.Add("@NewZz", zzs);
                    htable.Add("@mqdate", fbs);
                    htable.Add("@MQRJ", cont);


                    DataSet ds = Org.ReaderDataSet("sel_newsMQ_bylikes", htable);
                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow dbRow in ds.Tables[0].Rows)
                            {
                                if (dbRow["EditUrl"] != null)
                                {
                                    dbRow["EditUrl"] = "MQRJTJEdit.aspx?Command=Edit";
                                }

                                if (dbRow["ViewUrl"] != null)
                                {
                                    dbRow["ViewUrl"] = "MQRJTJEdit.aspx?Command=View";
                                }
                               
                            }
                        }
                    }
                    PostListS.DataSource = ds;
                    PostListS.DataBind();
                    this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

                }

                #endregion

            }
            catch (System.Exception pexp)
            {
                throw (pexp);
            }
            //最后进行Grid数据查询并填充
            finally
            {

                LPanel.RenderControl(e.Output);
            }
        }
    }
}